package org.datacoder.geocoding.datastructures.rectangles

import org.datacoder.geocoding.*
import org.datacoder.geocoding.datastructures.geoshapes.*
import org.datacoder.geocoding.jurisdiction.*

class RectanglesSequentialScan implements RectanglesContainingPointFinder {

    GeoRectangle[] geoRectangles
    int length

    public RectanglesSequentialScan(Collection<Jurisdiction> jurisdictions){
        length = jurisdictions.size()
        geoRectangles = new GeoRectangle[length]
        int i = 0
        for(juris in jurisdictions){
            geoRectangles[i++] = juris.toGeoRectangle()
        }
    }

    public Set<Jurisdiction> findRectanglesContainingPoint(GeoPoint gp){
        Set<Jurisdiction> jurisdictions = new HashSet<Jurisdiction>()
        for(int i = 0; i < length; i++){
            if(geoRectangles[i].containsGeoPoint(gp)){
                jurisdictions.add(geoRectangles[i].juris)
            }
        }
        return jurisdictions
    }

}

